package com.it2297.view;

import javax.swing.ButtonGroup;


import javax.swing.JDialog;
import javax.swing.JButton;
import javax.swing.JPanel;

import java.awt.BorderLayout;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JRadioButton;
import javax.swing.JComboBox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JSpinner;

import com.it2297.controller.CustomerController;
import com.it2297.controller.ProductController;
import javax.swing.DefaultComboBoxModel;
import javax.swing.border.EmptyBorder;

public class CreateCustomerView extends JDialog {
	private final CustomerController ccc = new CustomerController(this);
	private final ButtonGroup rbg = new ButtonGroup();
	private final JPanel contentPanel = new JPanel();
	private final JButton btnTest = new JButton("Sign Up");
	private final JTextField Name_Tf = new JTextField();
	private final JLabel lblNewLabel = new JLabel("Sign Up Page");
	private final JLabel lblNric = new JLabel("Name");
	private final JLabel lblNewLabel_1 = new JLabel("Gender");
	private final JTextField Email_Tf = new JTextField();
	private final JLabel lblEmail = new JLabel("Email");
	private final JTextField Contact_Tf = new JTextField();
	private final JLabel lblContactNumber = new JLabel("Contact Number");
	private final JTextField Address_Tf = new JTextField();
	private final JLabel lblAddress = new JLabel("Address");
	private final JComboBox race_CB = new JComboBox();
	private final JLabel lblRace = new JLabel("Race");
	private final JLabel lblDateOfBirth = new JLabel("Date of Birth");
	private final JLabel lblNric_1 = new JLabel("Identification Number");
	private final JTextField Nric_Tf = new JTextField();
	private final JComboBox cob_CB = new JComboBox();
	private final JLabel lblCountryOfBirth = new JLabel("Country of Birth");
	private final JLabel lblPassword = new JLabel("Password");
	private final JTextField password_TF = new JTextField();
	private final JTextField dob_TF = new JTextField();
	private final JComboBox gender_CB = new JComboBox();

	/**
	 * Create the panel.
	 */
	public CreateCustomerView() {
		this.setLocationRelativeTo(null);
		setBounds(100, 100, 800, 600);
		getContentPane().setLayout(null);
		contentPanel.setBounds(0, 0, 0, 0);
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel);
		dob_TF.setBounds(184, 232, 80, 20);
		dob_TF.setColumns(10);
		password_TF.setBounds(184, 430, 98, 22);
		password_TF.setColumns(10);
		Nric_Tf.setBounds(184, 176, 121, 23);
		Nric_Tf.setColumns(10);
		Address_Tf.setBounds(184, 368, 210, 41);
		Address_Tf.setColumns(10);
		Contact_Tf.setBounds(184, 322, 121, 23);
		Contact_Tf.setColumns(10);
		Email_Tf.setBounds(184, 277, 210, 23);
		Email_Tf.setColumns(10);
		Name_Tf.setBounds(184, 50, 210, 23);
		Name_Tf.setColumns(10);

		initGUI();
	}

	private void initGUI() {
		getContentPane().setLayout(null);
		btnTest.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				boolean vaild = ccc.create();
				System.out.println(vaild);
			}
		});
		btnTest.setBounds(178, 522, 89, 23);

		getContentPane().add(btnTest);

		getContentPane().add(Name_Tf);
		lblNewLabel.setFont(new Font("Arial", Font.BOLD, 15));
		lblNewLabel.setBounds(24, 11, 132, 23);

		getContentPane().add(lblNewLabel);
		lblNric.setFont(new Font("Arial", Font.PLAIN, 12));
		lblNric.setBounds(46, 53, 46, 14);

		getContentPane().add(lblNric);
		lblNewLabel_1.setFont(new Font("Arial", Font.PLAIN, 12));
		lblNewLabel_1.setBounds(46, 90, 46, 32);

		getContentPane().add(lblNewLabel_1);

		getContentPane().add(Email_Tf);
		lblEmail.setFont(new Font("Arial", Font.PLAIN, 12));
		lblEmail.setBounds(46, 282, 46, 14);

		getContentPane().add(lblEmail);

		getContentPane().add(Contact_Tf);
		lblContactNumber.setFont(new Font("Arial", Font.PLAIN, 12));
		lblContactNumber.setBounds(46, 327, 110, 14);

		getContentPane().add(lblContactNumber);

		getContentPane().add(Address_Tf);
		lblAddress.setFont(new Font("Arial", Font.PLAIN, 12));
		lblAddress.setBounds(46, 380, 59, 14);

		getContentPane().add(lblAddress);
		race_CB.setModel(new DefaultComboBoxModel(new String[] {"CHI", "MAL", "IND"}));
		race_CB.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				   race_CB.getSelectedItem();
					System.out.println(getRace());
			}
		});
		race_CB.setFont(new Font("Arial", Font.PLAIN, 12));
		race_CB.setBounds(184, 138, 89, 20);

		getContentPane().add(race_CB);
		lblRace.setFont(new Font("Arial", Font.PLAIN, 12));
		lblRace.setBounds(46, 133, 46, 30);

		getContentPane().add(lblRace);
		lblDateOfBirth.setFont(new Font("Arial", Font.PLAIN, 12));
		lblDateOfBirth.setBounds(46, 234, 81, 14);

		getContentPane().add(lblDateOfBirth);
		lblNric_1.setFont(new Font("Arial", Font.PLAIN, 12));
		lblNric_1.setBounds(46, 181, 128, 23);

		getContentPane().add(lblNric_1);

		getContentPane().add(Nric_Tf);
		cob_CB.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				   cob_CB.getSelectedItem();
					System.out.println(getCOB());
			}
		});
		cob_CB.setModel(new DefaultComboBoxModel(new String[] {"SGP", "MYS", "IND", "THA"}));
		cob_CB.setFont(new Font("Arial", Font.PLAIN, 12));
		cob_CB.setBounds(184, 482, 83, 20);

		getContentPane().add(cob_CB);
		lblCountryOfBirth.setFont(new Font("Arial", Font.PLAIN, 12));
		lblCountryOfBirth.setBounds(46, 485, 110, 14);

		getContentPane().add(lblCountryOfBirth);
		lblPassword.setFont(new Font("Arial", Font.PLAIN, 12));
		lblPassword.setBounds(46, 427, 81, 25);
		
		getContentPane().add(lblPassword);
		
		getContentPane().add(password_TF);
		
		getContentPane().add(dob_TF);
		gender_CB.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				   gender_CB.getSelectedItem();
					System.out.println(getGender());
			}
		});
		gender_CB.setModel(new DefaultComboBoxModel(new String[] {"Female", "Male"}));
		gender_CB.setFont(new Font("Arial", Font.PLAIN, 12));
		gender_CB.setBounds(184, 96, 89, 20);
		
		getContentPane().add(gender_CB);
	}
	public JPanel getContentPanel() {
		return contentPanel;
	}

	public String getNric() {
		return Nric_Tf.getText();
	}

	public String getName() {
		return Name_Tf.getText();
	}
	
	public String getAddress() {
		return Address_Tf.getText();
	}

	public String getPhone() {
		return Contact_Tf.getText();
	}

	public String getEmail() {
		return Email_Tf.getText();
	}
	
	public String getPassword() {
		return password_TF.getText();
	}
	
	public String getGender() {
		return (String) gender_CB.getSelectedItem();
	}

	public String getRace() {
		return (String) race_CB.getSelectedItem();
	}

	public String getCOB() {
		return (String) cob_CB.getSelectedItem();
	}

	/*public Date getDOB() {
		
	    
		SimpleDateFormat df = new SimpleDateFormat("dd/mm/yyyy");
		Date date = null;
		try {
			String dob = dob_TF.getText() + "00:00:00";
			date = df.parse(dob_TF.getText());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	       // System.out.println(startDate);
	        
	        
	 
		return date;
	}*/
	public Date getDOB(){
 DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
//		DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy"); 
		 Date date = null;
		try {
			date = (Date)formatter.parse(dob_TF.getText());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(date);
		 return date;
		
	}
	
	public void setDOB() {
		 DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
		 String reportDate = df.format(dob_TF);
		 dob_TF.setText(reportDate);
		}
	}
